home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / PacMan / PlayerUpView.m < prev    next >
Encoding:
Text File  |  1992-07-24  |  1.5 KB  |  71 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "PlayerUpView.h"
  5. #import <appkit/NXImage.h>
  6. #import <appkit/Control.h>
  7. #import <appkit/graphics.h>
  8. #import <dpsclient/psops.h>    // PSxxx functions
  9.  
  10. @implementation PlayerUpView
  11.  
  12. - initFrame:(const NXRect *)frm        // initialize instance
  13. {
  14.     [super initFrame:frm];
  15.     numUp = 0;
  16.     pacs = [NXImage findImageNamed:"Pacs.tiff"];
  17.     return self;
  18. }
  19.  
  20. - drawSelf:(NXRect *)rects :(int)rectCount  // standard rendering method
  21. {
  22.     // It is assumed that this view is exactly 96x80 pixels,
  23.     // which allows 6 pacs across and 5 pacs vertically.
  24.     // for now, they're at stationary locations.
  25.     int i;
  26.     NXRect from;
  27.     NXPoint pos;
  28.     
  29.     PSsetgray(0.666);
  30.     NXRectFill(&bounds);
  31.     NXSetRect(&from, 2 * PAC_SIZE, PAC_SIZE, PAC_SIZE, PAC_SIZE);
  32.     if (!numUp) return self;
  33.     for (i=0; i<=((numUp < 6) ? numUp - 1 : 5); i++) {
  34.     // figure out where to draw the Pac and then composite it onto the view
  35.         pos.x = (i % 3) * PAC_SIZE * 2 + PAC_SIZE / 2;
  36.         pos.y = (i / 3) * PAC_SIZE * 2 + PAC_SIZE;
  37.         [pacs composite:NX_SOVER fromRect:&from toPoint:&pos];
  38.     }
  39.     NXPing();
  40.     return self;
  41. }
  42.  
  43. - setNumUp:(int)num                // draw all fruits up to level
  44. {
  45.     if (numUp == num) return self;
  46.     numUp = num;
  47.     [self update];
  48.     return self;
  49. }
  50.  
  51. - incPacs        // add another pac to the bunch
  52. {
  53.     numUp++;
  54.     [self update];
  55.     return self;
  56. }
  57.  
  58. - (int)pacs    { return numUp; }    // return # pacs left
  59.  
  60. - (BOOL)nextPac    // if pacs left, decrement # pacs and return YES.
  61. {                // returns NO if no pacs left.
  62.     if (numUp) {
  63.         numUp--;
  64.         [self update];
  65.         return YES;
  66.     }
  67.     return NO;
  68. }
  69.  
  70. @end
  71.